﻿
<script type="text/javascript">   
    
    //显示当前日期
    formatterDate = function (date) {
        var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
        var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1);
        var hor = date.getHours();
        var min = date.getMinutes();
        var sec = date.getSeconds();
        return date.getFullYear() + '-' + month + '-' + day + " " + hor + ":" + min + ":" + sec;
    };
    $(function () {
        getButton("grave_ext");
    });
    var selectParadiseCode = "011";
    var selectLoc = "000";
    var isGht = true;
    function ui_grave_ext_init_list(toolbar) {
        var bLoaded = false;
        $('#ui_grave_ext_tree').tree({
            url:'ashx/bg_grave_ext.ashx?action=gettree',
            lines: true,
            method: 'get',
            animate: true,
            formatter:function(node){
                var s = node.text;
                if (node.children){
                    s += '&nbsp;<span style=\'color:blue\'>(' + node.children.length + ')</span>';
                }
                return s;
            },
            onContextMenu: function (e, node) {
                //if (node.code.length > 3) return;
                e.preventDefault();
                $(this).tree('select',node.target);
                $('#ui_grave_ext_mm').menu('show',{
                    left: e.pageX,
                    top: e.pageY
                });
            },
            onBeforeExpand:function(node){                
                $('#ui_grave_ext_tree').tree('options').queryParams = { id: node.id,code:node.code };
            },
            onClick: function (node) {
                isGht = node.isGht;
                selectParadiseCode = node.code.substring(0, 3);
                selectLoc = node.code;
                if ($('#ui_grave_ext_tree').tree('isLeaf', node.target)) {
                    
                }
                
                ui_grave_ext_searchdata2(node.code);
            },
            onLoadSuccess: function (node, data) {                
                if (!bLoaded && data && data.length > 0) {
                    $("#dlgLoading").hide();
                    bLoaded = true;
                    whereStr = data[0].code + '%';
                    isGht = data[0].isGht;
                    whereStr = "location like '" + whereStr + "'";
                    ui_grave_ext_init_datagrid(toolbar, whereStr);
                    selectLoc = data[0].code;
                }
            }
        });
        
    }

    function ui_grave_ext_init_datagrid(toolbar, whereStr) {
        $("#ui_grave_ext_dg").datagrid({       //初始化datagrid
            url: "ashx/bg_grave_ext.ashx?action=search",
            striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: false,
            idField: 'id',
            sortName: 'location',
            sortOrder: 'asc',
            pageList: [20, 40, 60, 80, 100],
            queryParams: {
                where: whereStr
            },
            columns: [[
                { field: 'columnNum', title: '穴位编号', sortable: true, width: 60 },
                { field: 'paradiseName', title: '骨灰堂', sortable: true, width: 120 },
                { field: 'name', title: '位置', width: 250 },
                { field: 'location', title: '位置编码', sortable: true, width: 120 },
                {
                    field: 'graveType', title: '类型', sortable: true, width: 40,
                    formatter: function (value, row, index) {
                        if (value == 2) { return "双"; }
                        else if (value > 2) { return "多"; }
                        else { return "单"; }
                    }
                },
                {
                    field: 'qty', title: '存放数量', sortable: true, width: 60,
                    formatter: function (value, row, index) {
                        if (value == 0) { return "<span style='color:#66ccff'>" + value + "</span>"; }
                        return "<span style='color:red'>" + value + "</span>";
                    }
                },
                { field: 'importloc', title: '原位置', sortable: true, width: 200 }

            ]],
            rowStyler: function (index, row) {
                if (row.qty == 0) {
                    return 'color:#66cc99;';
                }
            },
            toolbar: toolbar.length == 0 ? null : toolbar,   //请求回来的当前用户可以操作的按钮
            view: detailview,
            detailFormatter: function (index, row) {
                return '<div style="padding:2px"><table class="ddv"></table></div>';
            },
            onExpandRow: function (index, row) {
                var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                ddv.datagrid({
                    url: 'ashx/bg_dead.ashx?action=searchDead&graveId=' + row.id,
                    fitColumns: true,
                    singleSelect: true,
                    rownumbers: true,
                    loadMsg: '正在加载...',
                    idField: 'id',
                    sortName: 'deathtime',
                    sortOrder: 'asc',
                    height: 'auto',
                    columns: [[
                              { field: 'name', title: '死者姓名', width: 80 },
                              { field: 'areaName', title: '区域', width: 100 },
                              { field: 'homeAddress', title: '组别', width: 80 },
                              { field: 'relativeName', title: '亲属', width: 80 },
                              { field: 'relativeTel', title: '电话', width: 80 },
                              { field: 'relationId', title: '关系', width: 60 },
                              { field: 'storeTime', title: '存放时间', width: 150 },
                              { field: 'description', title: '备注', width: 150 }
                    ]],
                    onResize: function () {
                        $('#ui_grave_ext_dg').datagrid('fixDetailRowHeight', index);
                    },
                    onLoadSuccess: function () {
                        setTimeout(function () {
                            $('#ui_grave_ext_dg').datagrid('fixDetailRowHeight', index);
                        }, 0);
                    },
                    toolbar: [
                            {
                                id: "ui_grave_ext_store_dead_btn",
                                text: '寄存',
                                iconCls: 'icon-remove',
                                handler: function () {
                                    storeGraveDead_to_grave_ext(ddv, row, index);
                                }
                            }, {
                                id: "ui_grave_ext_edit_dead_btn",
                                text: '修改',
                                iconCls: 'icon-edit',
                                handler: function () {
                                    editGraveDead_to_grave_ext(ddv, row);
                                }
                            }, {
                                id: "ui_grave_ext_dead_clear_btn",
                                text: '清空',
                                iconCls: 'icon-remove',
                                handler: function () {
                                    ui_grave_ext_dead_clear(ddv, row);
                                }
                            }, {
                                id: "ui_grave_ext_dead_remove_btn",
                                text: '移除',
                                iconCls: 'icon-remove',
                                handler: function () {
                                    remove_dead_from_grave_ext(ddv, row);
                                }
                            }, {
                                id: "ui_grave_ext_dead_move_btn",
                                text: '迁移',
                                iconCls: 'icon-move',
                                handler: function () {
                                    move_dead_from_grave_ext(ddv, row);
                                }
                            }, {
                                id: "ui_grave_ext_dead_print_btn",
                                text: '二维码',
                                iconCls: 'icon-qrcode',
                                handler: function () {
                                    ui_grave_ext_dead_qrcode(ddv, row);
                                }
                            }
                    ]
                });
                $('#ui_grave_ext_dg').datagrid('fixDetailRowHeight', index);
            }
        });

    }

    function ui_grave_ext_add() {
        var url = 'html/ui_grave_edit.html';
        if (!isGht) {
            url = 'html/ui_grave_edit2.html';
        }
        $('<div/>').dialog({
            id: 'ui_grave_ext_add_dialog',
            href: url,
            title: '新增穴位',
            height: 220,
            width: 500,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_add_btn",
                text: '添 加',
                handler: function () {
                    $("#ui_grave_editform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {
                            $('#ui_grave_ext_add_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'add';
                            if ($(this).form('validate'))
                                return true;
                            else {
                                $('#ui_grave_ext_add_btn').linkbutton('enable');   //恢复按钮
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = eval('(' + data + ')');    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_add_dialog").dialog('destroy'); //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                $("#ui_grave_ext_dg").datagrid("reload");
                            } else {
                                $('#ui_grave_ext_add_btn').linkbutton('enable');   //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $('#ui_grave_edit_paradise_code').combotree('setValue', selectParadiseCode);
                var rows = $("#ui_grave_ext_dg").datagrid("getChecked");
                if (rows.length < 1) return;
                var row = rows[0];
                $('#ui_grave_edit_paradise_code').combotree('setValue', row.paradiseCode);
                $('#ui_grave_edit_hourseNum').numberbox('setValue', row.hourseNum);
                $('#ui_grave_edit_floorNum').numberbox('setValue', row.floorNum);
                $('#ui_grave_edit_sectionNum').textbox('setValue', row.sectionNum);
                $('#ui_grave_edit_lineNum').textbox('setValue', row.lineNum);
                $('#ui_grave_edit_rowNum').textbox('setValue', row.layerNum);
                $('#ui_grave_edit_colNum').textbox('setValue', row.columnNum);
                if (row.graveType)
                    $('#ui_grave_edit_type').combobox('setValue', row.graveType);
                $('#ui_grave_edit_price').numberbox('setValue', row.price);
                $('#ui_grave_edit_description').textbox('setValue', row.description);
                
            },
            onClose: function () {
                $("#ui_grave_ext_add_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }

    function ui_grave_ext_edit() {
        var url = 'html/ui_grave_edit.html';
        if (!isGht) {
            url = 'html/ui_grave_edit2.html';
        }
        var rows = $("#ui_grave_ext_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请先勾选要修改的行");
            return;
        }
        if (rows.length > 1) {
            $.show_warning("提示", "不支持批量修改");
            $("#ui_grave_ext_dg").datagrid('clearSelections').datagrid('clearChecked');
            return;
        }
        var row = rows[0];
        $('<div/>').dialog({
            id: 'ui_grave_ext_edit_dialog',
            href: url,
            title: '修改穴位',
            height: 220,
            width: 500,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_edit_btn",
                text: '修 改',
                handler: function () {
                    $("#ui_grave_editform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {
                            $('#ui_grave_ext_edit_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'edit';
                            if ($(this).form('validate'))
                                return true;
                            else {
                                $('#ui_grave_ext_edit_btn').linkbutton('enable');   //恢复按钮
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = eval('(' + data + ')');    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_edit_dialog").dialog('destroy'); //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                $("#ui_grave_ext_dg").datagrid("reload");
                            } else {
                                $('#ui_grave_ext_edit_btn').linkbutton('enable');   //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                                
                $('#ui_grave_edit_id').val(row.id);
                $('#ui_grave_edit_hourseNum').numberbox('setValue', row.hourseNum);
                $('#ui_grave_edit_floorNum').numberbox('setValue', row.floorNum);
                $('#ui_grave_edit_sectionNum').textbox('setValue', row.sectionNum);
                $('#ui_grave_edit_lineNum').textbox('setValue', row.lineNum);
                $('#ui_grave_edit_rowNum').textbox('setValue', row.layerNum);
                $('#ui_grave_edit_colNum').textbox('setValue', row.columnNum);
                if (row.graveType)
                    $('#ui_grave_edit_type').combobox('setValue', row.graveType);
                $('#ui_grave_edit_price').numberbox('setValue', row.price);
                $('#ui_grave_edit_description').textbox('setValue', row.description);
                //$('#ui_grave_edit_qty').numberbox('setValue', row.qty);
                $('#ui_grave_edit_paradise_code').combotree('setValue', row.paradiseCode);
            },
            onClose: function () {
                $("#ui_grave_ext_edit_dialog").dialog('destroy');  //销毁dialog对象
            }
        });

    }

    function ui_grave_ext_delete() {
        var rows = $("#ui_grave_ext_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请先勾选要删除的行");
            return;
        }
        $.messager.confirm('提示', '确定删除勾选的' + rows.length + '行？', function (r) {
            if (r) {
                para = {};
                para.action = "delete";
                para.timespan = new Date().getTime();
                para.id = "";
                var ids = [];
                $.each(rows, function (i, row) {
                    ids.push(row.id);
                });
                para.id = ids.join(",");
                $.ajax({
                    url: "ashx/bg_grave_ext.ashx",
                    data: para,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        if (data.success) {
                            $.show_warning("提示", data.msg);
                            $("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                        } else {
                            $.show_warning("提示", data.msg);
                        }
                    }
                });
            }
        });
    }

    //上传导入数据
    function ui_grave_ext_import() {

        $("<div/>").dialog({
            id: "ui_grave_ext_import_dialog",
            href: "html/ui_grave_ext_import.html",
            iconCls: "icon-filter",
            title: '数据导入',
            height: 240,
            width: 420,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_import_btn",
                text: '导入',
                iconCls: "icon-import",
                handler: function () {
                    $("#ui_grave_ext_importform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {
                            $('#ui_grave_ext_import_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            var chkAuto= $('#chkAutoCreateGrave').val();
                            param.action = 'import';
                            param.op = 'import';
                            param.autocreate=chkAuto;
                            if ($(this).form('validate')) {
                                $('#ui_grave_ext_importform_msg').html("正在导入，请稍候...");
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_import_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {                            
                            var dataJson = eval('(' + data + ')');    //转成json格式                                    
                            if (dataJson.success) {
                                $("#ui_grave_ext_import_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                $("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {                               
                                $('#ui_grave_ext_import_btn').linkbutton('enable');  //恢复按钮
                                $('#ui_grave_ext_importform_msg').html("导入出错:" + dataJson.msg );
                                $.show_alert("导入失败", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
            },
            onClose: function () {
                $("#ui_grave_ext_import_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }


    function ui_grave_ext_clear() {
        var rows = $("#ui_grave_ext_dg").datagrid("getChecked");
        if (rows.length != 1) {
            $.show_warning("提示", "请选择要清空的穴位");
            return;
        }
        var row = rows[0];
        if (row.qty < 1) {
            $.show_warning("提示", "没有骨灰寄存，不需要清空！");
            return;
        }

        $("<div/>").dialog({
            id: "ui_grave_ext_clear_dialog",
            href: "html/ui_grave_clear.html",
            iconCls: "icon-clear",
            title: '死者移除',
            height: 200,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_clear_btn",
                text: '移除',
                iconCls: "icon-clear",
                handler: function () {
                    $("#ui_grave_clearform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {
                            $('#ui_grave_ext_clear_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'clear';
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_clear_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_clear_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                $("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_clear_btn').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $('#ui_grave_id_clearform').val(row.id);
                $("#ui_grave_location_clearform").textbox('setValue', "[" + row.paradiseName + "] " + row.location);
                $("#ui_grave_remark_clearform").focus();
            },
            onClose: function () {
                $("#ui_grave_ext_clear_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }

    //清空穴位死者
    function ui_grave_ext_dead_clear(dg,grave) {
        
        $("<div/>").dialog({
            id: "ui_grave_ext_clear_dialog",
            href: "html/ui_grave_clear.html",
            iconCls: "icon-clear",
            title: '死者移除',
            height: 200,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_clear_btn",
                text: '移除',
                iconCls: "icon-clear",
                handler: function () {
                    $("#ui_grave_clearform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {
                            $('#ui_grave_ext_clear_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'clear';
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_clear_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_clear_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                dg.datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_clear_btn').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $('#ui_grave_id_clearform').val(grave.id);
                $("#ui_grave_location_clearform").textbox('setValue', "[" + grave.paradiseName + "] " + grave.location);
                $("#ui_grave_remark_clearform").focus();
            },
            onClose: function () {
                $("#ui_grave_ext_clear_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }

    function ui_grave_ext_store() {
        var rows = $("#ui_grave_ext_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请选择要存放的穴位所在行或者双击某行");
            return;
        }
        if (rows.length > 1) {
            $.show_warning("提示", "请只选择一行！");
            $("#ui_grave_ext_dg").datagrid('clearSelections').datagrid('clearChecked');
            return;
        }

        //if (!rows[0].relativeId) {
        //    $.show_warning("提示", "该穴位暂未登记，无法寄存，请先登记！");
        //    return;
        //}
        var row = rows[0];
        $("<div/>").dialog({
            id: "ui_grave_ext_store_dialog",
            href: "html/ui_grave_store.html",
            iconCls: "icon-sum",
            title: "骨灰寄存",
            height: 450,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_store_btn",
                text: '保存',
                iconCls: "icon-sum",
                handler: function () {
                    $("#ui_grave_storeform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {

                            $('#ui_grave_ext_store_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'store';
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_store_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_store_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                $("#ui_grave_ext_dg").datagrid("reload");
                                $("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_store_btn').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {

                $("#ui_grave_location").textbox('setValue', "[" + row.paradiseName + "] " + row.name);
                $('#ui_grave_id').val(row.id);
                var date = formatterDate(new Date());
                $("#ui_grave_starttime").datetimebox("setValue", date);
                //alert( row.id + "," + row.relativeId)
                get_relative_by_id_ext(row.relativeId);
                
                $("#ui_grave_dead_cardno").focus();
            },
            onClose: function () {
                $("#ui_grave_ext_store_dialog").dialog('destroy');  //销毁dialog对象
            }
        });        

    }

    function storeGraveDead_to_grave_ext(dg, row, index) {
        $("<div/>").dialog({
            id: "ui_grave_ext_store_dialog",
            href: "html/ui_grave_store.html",
            iconCls: "icon-sum",
            title: "骨灰寄存",
            height: 450,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_store_btn",
                text: '保存',
                iconCls: "icon-sum",
                handler: function () {
                    $("#ui_grave_storeform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {

                            $('#ui_grave_ext_store_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'store';
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_store_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_store_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);                                
                                $("#ui_grave_ext_dg").datagrid("reload");
                                dg.datagrid("reload");

                                //$("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_store_btn').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $("#ui_grave_location").textbox('setValue', "[" + row.paradiseName + "] " + row.name);
                $('#ui_grave_id').val(row.id);
                var date = formatterDate( new Date());                
                $("#ui_grave_starttime").datetimebox("setValue", date);
                get_relative_by_id_ext(row.relativeId);
                $("#ui_grave_dead_cardno").focus();
            },
            onClose: function () {
                $("#ui_grave_ext_store_dialog").dialog('destroy');  //销毁dialog对象
            }
        });

    }
    //修改穴位的死者
    function editGraveDead_to_grave_ext(dg, grave) {
        var deads = dg.datagrid("getChecked");
        if (deads.length != 1) {
            $.show_warning("提示", "请选择要一行进行修改！");
            return;
        }
        var dr = deads[0];
        $("<div/>").dialog({
            id: "ui_grave_ext_store_dialog",
            href: "html/ui_grave_store.html",
            iconCls: "icon-sum",
            title: "寄存修改",
            height: 430,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_store_btn",
                text: '保存',
                iconCls: "icon-sum",
                handler: function () {
                    $("#ui_grave_storeform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {

                            $('#ui_grave_ext_store_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'store';
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_store_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_store_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                dg.datagrid("reload");
                                //$("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_store_btn').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }, {
                id: "ui_grave_ext_store_btn2",
                text: '修改联系人保存',
                iconCls: "icon-save",
                handler: function () {
                    $("#ui_grave_storeform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {

                            $('#ui_grave_ext_store_btn2').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'store';
                            param.op = "newrelative";
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_store_btn2').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_store_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                dg.datagrid("reload");
                                //$("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_store_btn2').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }
            ],
            onLoad: function () {
                $("#ui_grave_location").textbox('setValue', "[" + grave.paradiseName + "] " + grave.name);
                $('#ui_grave_id').val(grave.id);                
                get_relative_by_id_ext(dr.relativeId);
                if (!dr.storeTime) {
                    $('#ui_grave_notsave').attr("checked",true);
                }
                $("#ui_grave_starttime").datetimebox("setValue", dr.storeTime);
                $('#ui_grave_dead_id').val(dr.id);
                $('#ui_grave_dead_cardno').textbox('setValue', dr.cardno);
                $('#ui_grave_dead_name').textbox('setValue', dr.name);
                $('#ui_grave_dead_gender').textbox('setValue', dr.gender);
                $('#ui_grave_dead_nation').textbox('setValue', dr.nationId);
                $('#ui_grave_dead_addr').textbox('setValue', dr.homeAddress);
                $('#ui_grave_dead_desc').textbox('setValue', dr.description);
                $('#ui_grave_dead_firetime').datetimebox('setValue', dr.actFiretime);
                $('#ui_grave_dead_areaId').combotree('setValue', dr.areacode);
                $('#ui_grave_relative_relation').textbox('setValue', dr.relationId);
                $("#ui_grave_dead_cardno").focus();
            },
            onClose: function () {
                $("#ui_grave_ext_store_dialog").dialog('destroy');  //销毁dialog对象
            }
        });

    }
    //迁移
    function ui_grave_ext_move() {
        var rows = $("#ui_grave_ext_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请选择要迁移的穴位！");
            return;
        }
        if (rows.length > 1) {
            $.show_warning("提示", "请只选择一行！");
            $("#ui_grave_ext_dg").datagrid('clearSelections').datagrid('clearChecked');
            return;
        }
        var row = rows[0];
        if (row.qty < 1) {
            $.show_warning("提示", "没有骨灰寄存，不能迁移！");
            return;
        }
        var url = "html/ui_grave_move.html";

        if (!isGht) {
            url = "html/ui_grave_move2.html";
        }
        $("<div/>").dialog({
            id: "ui_grave_ext_move_dialog",
            href: url,
            iconCls: "icon-move",
            title: '穴位迁移',
            height: 300,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_move_btn",
                text: '迁移',
                iconCls: "icon-move",
                handler: function () {
                    $("#ui_grave_moveform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {

                            $('#ui_grave_ext_move_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'move';
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_move_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_move_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                $("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_move_btn').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $('#ui_grave_id_moveform').val(row.id);
                $("#ui_grave_location_moveform").textbox('setValue', "[" + row.paradiseName + '] ' + row.name);
                $("#ui_grave_paradise_code_moveform").combotree("setValue", row.paradiseCode);
                $('#ui_grave_hourseNum_moveform').numberbox("setValue", row.hourseNum);
                $('#ui_grave_floorNum_moveform').numberbox("setValue", row.floorNum);
                $('#ui_grave_sectionNum_moveform').textbox("setValue", row.sectionNum);
                $('#ui_grave_lineNum_moveform').textbox("setValue", row.lineNum);
                $('#ui_grave_rowNum_moveform').textbox("setValue", row.layerNum);
                $('#ui_grave_colNum_moveform').textbox("setValue", row.columnNum);
            },
            onClose: function () {
                $("#ui_grave_ext_move_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }

    //单个死者迁移
    function move_dead_from_grave_ext(dg,grave) {
        var rows = dg.datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请选择要迁移的死者！");
            return;
        }
        if (rows.length > 1) {
            $.show_warning("提示", "请只选择一个死者！");
            dg.datagrid('clearSelections').datagrid('clearChecked');
            return;
        }
        var row = rows[0];
        var url = "html/ui_grave_move.html";

        if (!isGht) {
            url = "html/ui_grave_move2.html";
        }
        $("<div/>").dialog({
            id: "ui_grave_ext_move_dialog",
            href: url,
            iconCls: "icon-move",
            title: '死者迁移',
            height: 300,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_move_btn",
                text: '迁移',
                iconCls: "icon-move",
                handler: function () {
                    $("#ui_grave_moveform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {

                            $('#ui_grave_ext_move_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'move';
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_move_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_move_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                //$("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                dg.datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_move_btn').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $('#ui_grave_id_moveform').val(grave.id);
                $('#ui_dead_id_moveform').val(row.id);                
                $("#ui_grave_location_moveform").textbox('setValue', "[" + grave.paradiseName + "] " + grave.name);

                $("#ui_grave_paradise_code_moveform").combotree("setValue", grave.paradiseCode);
                $('#ui_grave_hourseNum_moveform').numberbox("setValue", grave.hourseNum);
                $('#ui_grave_floorNum_moveform').numberbox("setValue", grave.floorNum);
                $('#ui_grave_sectionNum_moveform').textbox("setValue", grave.sectionNum);
                $('#ui_grave_lineNum_moveform').textbox("setValue", grave.lineNum);
                $('#ui_grave_rowNum_moveform').textbox("setValue", grave.layerNum);
                $('#ui_grave_colNum_moveform').textbox("setValue", grave.columnNum);
            },
            onClose: function () {
                $("#ui_grave_ext_move_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }
    //从穴位中移除死者
    function remove_dead_from_grave_ext(dg, grave) {

        var rows = dg.datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请选择要移除的行");
            return;
        }
        var row = rows[0];
        $("<div/>").dialog({
            id: "ui_grave_ext_clear_dialog",
            href: "html/ui_grave_clear.html",
            iconCls: "icon-clear",
            title: '死者移除',
            height: 200,
            width: 620,
            modal: true,
            buttons: [{
                id: "ui_grave_ext_clear_btn",
                text: '移除',
                iconCls: "icon-clear",
                handler: function () {
                    $("#ui_grave_clearform").form("submit", {
                        url: "ashx/bg_grave_ext.ashx",
                        onSubmit: function (param) {

                            $('#ui_grave_ext_clear_btn').linkbutton('disable');    //点击就禁用按钮，防止连击
                            param.action = 'clear';
                            if ($(this).form('validate')) {
                                return true;
                            }
                            else {
                                $('#ui_grave_ext_clear_btn').linkbutton('enable');   //恢复按钮                                
                                return false;
                            }
                        },
                        success: function (data) {
                            var dataJson = JSON.parse(data);    //转成json格式
                            if (dataJson.success) {
                                $("#ui_grave_ext_clear_dialog").dialog('destroy');  //销毁dialog对象
                                $.show_warning("提示", dataJson.msg);
                                dg.datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                $("#ui_grave_ext_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $('#ui_grave_ext_clear_btn').linkbutton('enable');  //恢复按钮
                                $.show_warning("提示", dataJson.msg);
                            }
                        }
                    });
                }
            }],
            onLoad: function () {
                $('#ui_grave_id_clearform').val(grave.id);
                $('#ui_dead_id_clearform').val(row.id);                
                $("#ui_grave_location_clearform").textbox('setValue', "[" + grave.paradiseName + "] " + grave.name);
                $("#ui_grave_remark_clearform").focus();
            },
            onClose: function () {
                $("#ui_grave_ext_clear_dialog").dialog('destroy');  //销毁dialog对象
            }
        });
    }
    function ui_grave_ext_dead_qrcode(dg, grave) {
        var rows = dg.datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请选择要位死者");
            return;
        }
        var row = rows[0];
        var url = "ashx/queryqrcode.aspx?ids=" + row.id;
        window.open(url,"_qrcode"+row.code);
        //window.location = "ashx/queryqrcode.aspx?code=" + row.code;
    }

    function ui_grave_ext_init() {
        $.show_warning("提示", "功能未实现");
    }



    function ui_grave_ext_searchdata2(whereStr) {        
        whereStr += '%';
        whereStr = "location like '" + whereStr + "'";
        
        $('#ui_grave_ext_dg').datagrid("load", { where: whereStr });
    }
    
    function ui_grave_ext_searchdata() {

        //var areacode = $('#ui_grave_ext_area').combotree('getValue');       
        var deadname = $('#ui_grave_ext_deadname').textbox('getValue');
        var deadcode = $('#ui_grave_ext_deadcode').textbox('getValue');
        var relativename = $('#ui_grave_ext_relativename').textbox('getValue');
        var relativetel = $('#ui_grave_ext_relativetel').textbox('getValue');

        var paradiseCode = $('#ui_grave_ext_paradise_code').combotree('getValue');        
        var hourseNum = $('#ui_grave_ext_hourseNum').textbox('getValue');
        var floorNum = $('#ui_grave_ext_floorNum').textbox('getValue');
        var sectionNum = $('#ui_grave_ext_sectionNum').textbox('getValue');
        var lineNum = $('#ui_grave_ext_lineNum').textbox('getValue');
        var layerNum = $('#ui_grave_ext_rowNum').textbox('getValue');
        var colNum = $('#ui_grave_ext_colNum').textbox('getValue');
        var status = $('#ui_grave_ext_status').combobox('getValue');
      
        var whereStr = "1=1";
        /* 
        if (paradiseCode) {
            whereStr = paradiseCode;
        } else {
            whereStr = '___';
        }
        if (hourseNum) {
            whereStr += hourseNum;
        } else {
            whereStr += '_';
        }
        if (floorNum) {
            whereStr += floorNum;
        } else {
            whereStr += '_';
        }
        if (sectionNum) {
            whereStr += to2digit(sectionNum);
        } else {
            whereStr += '__';
        }
        if (lineNum) {
            whereStr += to2digit(lineNum);
        } else {
            whereStr += '__';
        }
        if (layerNum) {
            whereStr += to2digit(layerNum);
        } else {
            whereStr += '__'
        }
        if (colNum) {
            whereStr += to3digit(colNum);
        } else {
            whereStr += '___';
        }
        whereStr += '_';
        whereStr = "location like '" + whereStr + "'";
        if (status == "1") {    //未存放
            whereStr += " and qty=0"
        } else if (status == '2') {
            whereStr += " and qty>0"
        }
*/
        //alert(whereStr);

        $('#ui_grave_ext_dg').datagrid("load",
            {
                where: whereStr, status: status, paradiseCode: paradiseCode, hourseNum: hourseNum, floorNum: floorNum,
                sectionNum: sectionNum, lineNum: lineNum, layerNum: layerNum, colNum: colNum,
                deadcode: deadcode, deadname: deadname, relativename: relativename, relativetel: relativetel
            });
    }

    function ui_grave_ext_cleardata() {
        $('#ui_grave_ext_search input').val('');
        $('#ui_grave_ext_search select').val('select');
        $("#ui_grave_ext_dg").datagrid('load', {});

        $("#ui_grave_ext_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_grave_search').layout('collapse', 'east');    //隐藏
    }

    function ui_grave_ext_refresh() {

        $('#ui_grave_ext_dg').datagrid("reload");
    }

    function to2digit(v) {
        return (Array(2).join(0) + v).slice(-2);
    }
    function to3digit(v) {
        return (Array(3).join(0) + v).slice(-3);
    }

    

    function get_relative_by_id_ext(relativeId) {
        if (!relativeId) return;
        para = {};
        para.action = "getRelativeById";
        para.timespan = new Date().getTime();
        para.relativeId = relativeId;
        $.ajax({
            url: "ashx/bg_relative.ashx",
            data: para,
            type: "POST",
            dataType: "json",
            success: function (data) {
                var dr = data.msg;
                if (data.success && dr) {
                    $('#ui_grave_relative_id').val(dr.id);
                    $('#ui_grave_relative_name').textbox('setValue', dr.name);
                    $('#ui_grave_relative_tel').textbox('setValue', dr.tel);
                    $('#ui_grave_relative_areaId').combotree('setValue', dr.areacode);
                    $('#ui_grave_relative_cardno').textbox('setValue', dr.cardno);
                }
            }
        });
    }
  
    function ui_grave_ext_tree_refresh() {
        var node = $('#ui_grave_ext_tree').tree('getSelected');
        $('#ui_grave_ext_tree').tree('options').queryParams = { t: (new Date()).getTime(),id:node.id };
        $('#ui_grave_ext_tree').tree('reload', node.target);
        //var pn = $('#ui_grave_ext_tree').tree('getParent', node.target);
        //if (node == null) {
        //    $('#ui_grave_ext_tree').tree('options').queryParams = {  };
        //    $('#ui_grave_ext_tree').tree('reload', null);
        //} else {
        //    $('#ui_grave_ext_tree').tree('options').queryParams = { id: node.id };
        //    $('#ui_grave_ext_tree').tree('reload', node.target);
        //}                    
    }
    function ui_grave_ext_tree_expand() {
        var node = $('#ui_grave_ext_tree').tree('getSelected');
        $('#ui_grave_ext_tree').tree('expandAll', node.target);
    }
    function ui_grave_ext_tree_collapse() {
        var node = $('#ui_grave_ext_tree').tree('getSelected');
        $('#ui_grave_ext_tree').tree('collapseAll', node.target);
    }

    function ui_grave_ext_export() {
        var node = $('#ui_grave_ext_tree').tree('getSelected');
        var loc = selectLoc;
        if (node) {
            loc = node.code;
        }
        var url = "ashx/bg_grave_ext.ashx?action=export&loc=" + loc;
        $('#ui_grave_ext_export_excel').attr('src', url);        
    }

    //处理输入编码后回车搜索
    function ui_grave_ex_keyEnter(e) {
        if (e.keyCode == 13) {
            var code = $('#ui_grave_ext_deadcode').textbox("getValue");
            var x = code.indexOf("=");
            if (x > 0) {
                code = code.substr(x + 1);
                $('#ui_grave_ext_deadcode').textbox("setValue", code);
            }
            if (code && code.length > 0) {
                ui_grave_ext_searchdata();
            }
        }
    }
</script>
<div id="ui_grave_ext_layout" class="easyui-layout" data-options="fit:true,border:false">    
    <div data-options="region:'west',split:true,border:true" title="骨灰堂" style="width:180px" >
        <div id="dlgLoading">正在加载数据，请稍候...</div>
        <ul id="ui_grave_ext_tree"></ul>
        <div id="ui_grave_ext_mm" class="easyui-menu" style="width:120px;">
            <div onclick="ui_grave_ext_export()" data-options="iconCls:'icon-export'">导出名册</div>
            <div onclick="ui_grave_ext_tree_refresh()" data-options="iconCls:'icon-refresh'">刷新</div>
            <div class="menu-sep"></div>
            <div onclick="ui_grave_ext_tree_expand()" data-options="iconCls:'icon-expand'">展开</div>
            <div onclick="ui_grave_ext_tree_collapse()" data-options="iconCls:'icon-collapse'">收起</div>
        </div>
    </div>

    <div data-options="region:'center',border:false">
        <div style="display:none"><iframe id="ui_grave_ext_export_excel" style="display:none"></iframe></div>
        <table id="ui_grave_ext_dg" data-options="fit:true,border:false">
        </table>
    </div>
    <div data-options="region:'east',split:true,border:true,collapsed:true" title="多条件查询"
        style="width: 280px;">
        <div id="ui_grave_ext_search">
            <table class="tableForm" style="width: 100%; height: 100%; background: #F5F5F5;">
                <!--tr>
                    <th>联系人村委：</th>
                    <td>
                        <input type="hidden" value="1=1" name="ui_grave_ext_where" id="ui_grave_ext_where" />
                        <input class="easyui-combotree" id="ui_grave_ext_area" name="ui_grave_ext_area"
                            data-options="url: 'ashx/bg_area.ashx?action=getall', lines:true" />
                    </td>
                </tr-->
                <tr>
                    <th>联系人姓名：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_relativename" name="ui_grave_ext_relativename">
                    </td>
                </tr>
                <tr>
                    <th>联系人电话：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_relativetel" name="ui_grave_ext_relativetel">
                    </td>
                </tr>
                <tr>
                    <th>死者姓名：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_deadname" name="ui_grave_ext_deadname">
                    </td>
                </tr>
                <tr>
                    <th>死者编码：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_deadcode" data-options="events:{keyup:ui_grave_ex_keyEnter}"  name="ui_grave_ext_deadcode">
                    </td>
                </tr>
                <tr>
                    <th>骨灰堂：</th>
                    <td>
                        
                        <input class="easyui-combotree" id="ui_grave_ext_paradise_code" name="ui_grave_ext_paradise_code"
                            data-options="url: 'ashx/bg_paradise.ashx?action=getall', lines:true" />
                    </td>
                </tr>
                <tr>
                    <th>状态：</th>
                    <td>
                        <select class="easyui-combobox"  name="ui_grave_ext_status" id="ui_grave_ext_status" data-options="panelHeight:65,editable:false">
                            <option value="0">全部</option>
                            <option value="1">未存放</option>
                            <option value="2">已存放</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>橦号：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_hourseNum" name="ui_grave_ext_hourseNum">
                    </td>
                </tr>
                <tr>
                    <th>楼层：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_floorNum" name="ui_grave_ext_floorNum" >
                    </td>
                </tr>
                <tr>
                    <th>区：
                    </th>
                    <td>
                        <input type="text" class="easyui-textbox" name="ui_grave_ext_sectionNum" id="ui_grave_ext_sectionNum" />
                    </td>
                </tr>
                <tr>
                    <th>排：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_lineNum" name="ui_grave_ext_lineNum" >
                    </td>
                </tr>
                <tr>
                    <th>层：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_rowNum" name="ui_grave_ext_rowNum" >
                    </td>
                </tr>
                <tr>
                    <th>号：</th>
                    <td>
                        <input type="text" class="easyui-textbox" id="ui_grave_ext_colNum" name="ui_grave_ext_colNum">
                    </td>
                </tr>
                <tr>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                            onclick="ui_grave_ext_searchdata();">搜索</a>
                    </td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                            onclick="ui_grave_ext_cleardata();">清空条件</a>
                    </td>
                </tr>

            </table>
        </div>
    </div>

</div>
